import JsonData from "../../Json.js";
let { brideName, groomName, sharePhoto}=JsonData.invite;
Page({
    data: {
      staticUrl: getApp().globalData.staticUrl,
      currentIndex: 1,
      activeIndex: 0,
      indicatorDots: false,
      autoplay: false,
      interval: 5000,
      duration: 1000,
      circular: false,
      current: 1,
      isShowBadge: "none",
      isShowBadge2: "none",
      time: "",
      date: "",
      day: "",
      timer: "",
      receivedTimeArr: "",
      wallpaper: JsonData.configure.wallpaper,
      groomName: groomName
    },
    changeIndicatorDots: function(e) {
        this.setData({
            indicatorDots: !this.data.indicatorDots
        });
    },
    changeAutoplay: function(e) {
        this.setData({
            autoplay: !this.data.autoplay
        });
    },
    intervalChange: function(e) {
        this.setData({
            interval: e.detail.value
        });
    },
    durationChange: function(e) {
        this.setData({
            duration: e.detail.value
        });
    },
    toWeChat: function(e) {
      this.setData({
          currentIndex: e.detail.current
      });
      let title = "";
      if (!e.detail.current){
        switch (this.data.paramBtoA) {
          case 1:
            title ="通讯录";
            break
          case 2:
            title = "发现";
            break
          case 3:
            title = "我";
            break
          default:
            title = "微信";
            break
        }
        wx.setNavigationBarColor({
          frontColor: "#ffffff",
          backgroundColor: "#2E3038"
        })
      }else{
        title="";
        wx.setNavigationBarColor({
          frontColor: "#ffffff",
          backgroundColor: "#000"
        })
      }
      wx.setNavigationBarTitle({title});
    },
    onReady: function() {
      this.setData({
          isShowBadge: "block",
          isShowBadge2: "block"
      }), wx.vibrateLong();
      let receivedTimeArr = this.getTime();
      this.setData({
        receivedTimeArr: receivedTimeArr,
        time: receivedTimeArr[0],
        date: receivedTimeArr[1],
        day: receivedTimeArr[2]
      });
    },
    onLoad: function() {
        let than = this;
        clearInterval(this.data.timer);
        this.data.timer = setInterval(function() {
        let receivedTimeArr = than.getTime();
          than.setData({
              time: receivedTimeArr[0],
              date: receivedTimeArr[1],
              day: receivedTimeArr[2]
            });
        }, 1000);
    },
    onUnload: function() {
        clearInterval(this.data.timer);
    },
    onHide: function() {
        clearInterval(this.data.timer);
    },
    getTime: function() {
      let date = new Date();
      let hours= date.getHours();
      let minute = date.getMinutes();
      minute = minute < 10 ? "0" + minute : minute;
      let yaer=date.getFullYear();
      let month = date.getMonth() + 1;
      let day=  date.getDate();
      return [hours + ":" + minute, day = month+ "月" + day + "日", "星期" + "日一二三四五六".charAt(new Date().getDay()) ];
    },
    onShareAppMessage: function(e) {
        return "button" === e.from && console.log(e.target), {
          title: `${brideName}&${groomName}的结婚邀请函`,
          path: "pages/index/index",
          imageUrl: sharePhoto,
            success: function(res) {
                console.log("转发成功:" + JSON.stringify(res));
            },
            fail: function(err) {
                console.log("转发失败:" + JSON.stringify(err));
            }
        };
    },
    onMyEvent: function(e) {
        this.setData({
            paramBtoA: e.detail.paramBtoA
        });
    },
    hideBadgeEvent: function() {
        this.setData({
            isShowBadge: "none"
        });
    },
    hideBadgeEvent2: function() {
        this.setData({
            isShowBadge2: "none"
        });
    }
});